#ifndef SAFE_THREAD_QUEUE_H
#define SAFE_THREAD_QUEUE_H

#include "QMutex"
#include "QQueue"


template<typename T>
class safe_thread_queue
{
public:

    void enqueue(const T& value)
    {
        QMutexLocker locker(&m_mutex);
        m_queue.enqueue(value);
    }

    T dequeue()
    {
        QMutexLocker locker(&m_mutex);
        if (m_queue.isEmpty())
        {
            return T();
        }
        return m_queue.dequeue();
    }

    bool isEmpty() const
    {
        QMutexLocker locker(&m_mutex);
        return m_queue.isEmpty();
    }

    int size() const
    {
        QMutexLocker locker(&m_mutex);
        return m_queue.size();
    }

    void clear()
    {
        QMutexLocker locker(&m_mutex);
        m_queue.clear();
    }


private:
    QQueue<T> m_queue;
    mutable QMutex m_mutex;
};


#endif
